﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ANLP.Parser;
using System.IO;
using System.Text;

namespace ANLP.ParserGenerator
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            StringBuilder sb = new StringBuilder();
            ANLP.Parser.ParserGenerator.Generate(new StringReader(@"
%Namespace Turtle.Generated
%Visibility public
%ExpressionType Program
%token Up,Down,Move,Number,Comma
%using ANLP.Sample.Expressions
%%

private void GetX()
{
    int result;
    lexer.TryGet(out result);
    ((MoveStatement)block.Statements[block.Statements.Count - 1]).X = result;
}

private void GetY()
{
    int result;
    lexer.TryGet(out result);
    ((MoveStatement)block.Statements[block.Statements.Count - 1]).Y = result;
}

private void AddStatement(Statement statement)
{
    switch (statement.StatementType)
    {
        case Statements.Up:
        case Statements.Down:
        case Statements.Move:
            block.Statements.Add(statement);
            break;
        case Statements.Block:
            if (block == null)
                block = (BlockStatement)statement;
            program = (Program)statement;
            break;
        default:
            break;
    }
}

BlockStatement block;


%%

Program: { AddStatement(new Program()); } Statements; Statements:Statements Statement | Statement; Statement:Up { AddStatement(new UpStatement()); }|Down { AddStatement(new DownStatement()); }|Move { AddStatement(new MoveStatement()); } Number { GetX(); }Comma Number { GetY();};"), new StringWriter(sb));
            output.Text = sb.ToString();
        }
    }
}
